/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @param {number} targetSum
 * @return {number[][]}
 */
 var pathSum = function(root, targetSum) {
    const getPath = function(root,count,path){
      if(!root.left && !root.right && count === 0){
        path.push(root.val)
        pathList.push([].concat(path))
        return
      }
      if(!root.val && !root.right){
        return
      }
      path.push(root.val)
      if(root.left){
        getPath(root.left,count - root.left.val,path)
        path.pop()
      }
      if(root.right){
        getPath(root.right,count - root.right.val,path)
        path.pop()
      }
    }
    let pathList = []
    if(root === null) return []
    getPath(root,targetSum - root.val,[])
    return pathList
};